A bit more about relational data

STAT 331

Inner Join

Matches all pairs of observations when “keys” are equal

Mean Weights

surveys_weight <- surveys |>
  drop_na(weight) |> 
  group_by(species_id) |> 
  summarize(mean_weight = mean(weight))
species_id mean_weight
BA 8.60000
DM 43.15786
DO 48.87052
DS 120.13055
NL 159.24566
OL 31.57526

Adding Information

surveys_weight |> 
  inner_join(species, by = "species_id")
species_id mean_weight genus species taxa
BA 8.60000 Baiomys taylori Rodent
DM 43.15786 Dipodomys merriami Rodent
DO 48.87052 Dipodomys ordii Rodent
DS 120.13055 Dipodomys spectabilis Rodent
NL 159.24566 Neotoma albigula Rodent

Mutating joins

  • Left Join: Everything is kept in the dataset on the left

  • Right Join: Everything is kept in the dataset on the right

  • Full Join: Everything is kept in both datasets

Handy Helpers


rename()

Change names of columns


separate()

Separate values of a variable

Some words about resources

Using

Learning

A vignette…

Some words about functions

Has a better alternative available and is scheduled for removal.

Has a known better alternative, but the function itself is not going away.